package com.mmlc.meimei.lichengkongjian.classify;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.androidnetframe.httputil.BaseRequestFilterLayer;
import com.androidnetframe.responsejavabean.RequestError;
import com.mmlc.inter.InterActivity;
import com.mmlc.meimei.lichengkongjian.Adapter.PhysicalStoreAdapter;
import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.network.filter.PhysicalStoreListRequestFilter;
import com.mmlc.network.responsebean.PhysicalStoreListResponseBean;
import com.mmlc.utils.XUtils;
import com.mmlc.widget.MyListView;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class PhysicalStoreActivity extends InterActivity {


    @InjectView(R.id.tv_title)
    TextView mTvTitle;
    @InjectView(R.id.iv_back)
    ImageView mIvBack;
    @InjectView(R.id.tv_verify)
    TextView mTvVerify;
    @InjectView(R.id.rl_title)
    RelativeLayout mRlTitle;
    @InjectView(R.id.iv_store)
    ImageView mIvStore;
    @InjectView(R.id.mlv_stor)
    MyListView mMlvStor;
    @InjectView(R.id.activity_physical_store)
    LinearLayout mActivityPhysicalStore;

    private PhysicalStoreAdapter mAdapter;

    private String brandId;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (savedInstanceState == null)
            brandId = getIntent().getStringExtra("id");
        else
            brandId = savedInstanceState.getString("id");
        super.onCreate(savedInstanceState);

    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putString("id", brandId);
    }

    @Override
    protected int initContentView() {
        return R.layout.activity_physical_store;
    }

    @Override
    protected void initView() {
        ButterKnife.inject(this);
        mIvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        getData();
    }

    private void getData() {
        PhysicalStoreListRequestFilter filter = new PhysicalStoreListRequestFilter(this);
        filter.requestBean.brand_id = brandId;
        filter.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<PhysicalStoreListResponseBean>() {
            @Override
            public void onSuccess(PhysicalStoreListResponseBean result) {
                if (result != null) {
                    getDataSuccess(result.getData());
                }
            }

            @Override
            public void onFailed(View errorLayout, RequestError serverError, int failedType) {

            }
        });

    }

    private void getDataSuccess(PhysicalStoreListResponseBean.DataBean data) {
        if (data != null) {
            XUtils.image(mIvStore, data.getBrand().getShop_pc(), XUtils.getImageOptionsBuilder().setImageScaleType(ImageView.ScaleType.FIT_CENTER).build());
            mAdapter = new PhysicalStoreAdapter(this, data.getStore());
            mMlvStor.setAdapter(mAdapter);
        }
    }


}
